Skip to content

app: add support to hidden minimize and maximize buttons on macos and … #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kkeybbs
Copy link

@kkeybbs kkeybbs commented Aug 29, 2024

Two options app.HiddenMinimizeButton and app.HiddenMaximizeButton are added to create a window without minimize or/and maximize buttons.

hide both minimize and maximize buttons

w := new(app.Window)
w.Option(app.HiddenMinimizeButton(true), app.HiddenMaximizeButton(true))
image

hide minimize button, keep maximize button:

w := new(app.Window)
w.Option(app.HiddenMinimizeButton(true), app.HiddenMaximizeButton(false))
  • on macOS:
image
  • on Windows:
image

app/os.go Outdated
Comment on lines 49 to 52
// HiddenMinimizeButton hide the window's minimize button
HiddenMinimizeButton bool
// HiddenMaximizeButton hide the window's maximize button
HiddenMaximizeButton bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should either note that these don't work under Linux, or make them work under Linux.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried for days to test on ubuntu with os_x11.go, but still not working.

  • _NET_WM_ALLOWED_ACTIONS
  • _MOTIF_WM_HINTS
  • _NET_WM_WINDOW_TYPE: _NET_WM_WINDOW_TYPE_DIALOG

They all didn't work. I belive these properties also depend on window manager implementation, according to infomations bellow:

I'll continue wokring to make them work on x11 and wayland, but this may take long time.
So I add tips "only works for windows and macOS" for the options.
Maybe the feature working only on some os is acceptable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the feature working only on some os is acceptable?

Fine with me. Better than nothing! Thanks for trying.

@eliasnaur
Copy link
Contributor

Can you describe the use-cases you need these controls for? Can we just automatically apply them when, say, MinSize == MaxSize?

@kkeybbs
Copy link
Author

kkeybbs commented Sep 9, 2024

Can you describe the use-cases you need these controls for? Can we just automatically apply them when, say, MinSize == MaxSize?

Some usefull cases in my business products:

  • using both HiddenMaximizeButton and HiddenMinimizeButton
    • Making a dialog window, such as application's "About" dialog. Just need closing insteadof minimizing and maximizing.
    • Instead of minimizing to Dock, user can click the app, and makes it work in the background and an icon in the systray. Users like this easy experience, it saves spaces in Dock.
  • using HiddenMaximizeButton, to disallow a window to be a fullscreen window in new desktop on macOS.

So maybe I can try how to make a window be dialog in x11.

Sometimes HiddenMaximizeButton can be automatically apply with "MinSize == MaxSize", but not always when size is screen size. Maximizing will make the window as a new fullscreen window in macOS. So leave them standalone will be better.

@eliasnaur
Copy link
Contributor

Sorry for the slow response; I'm unusually busy these days.

Can you describe the use-cases you need these controls for? Can we just automatically apply them when, say, MinSize == MaxSize?

Some usefull cases in my business products:

* using both HiddenMaximizeButton and HiddenMinimizeButton
  
  * Making a dialog window, such as application's "About" dialog. Just need closing insteadof minimizing and maximizing.
  * Instead of minimizing to Dock, user can click the app, and makes it work in the background and an icon in the systray. Users like this easy experience, it  saves spaces in Dock.

* using HiddenMaximizeButton, to disallow a window to be a fullscreen window in new desktop on macOS.

Upon further though, perhaps the rules could be:

  • If MinSize != {0, 0}, hide/disable minimize button
  • If MaxSize != {0, 0}, hide/disable maximize button.

What do you think?

So maybe I can try how to make a window be dialog in x11.

Sometimes HiddenMaximizeButton can be automatically apply with "MinSize == MaxSize", but not always when size is screen size. Maximizing will make the window as a new fullscreen window in macOS. So leave them standalone will be better.

Can you elaborate? What is special about the screen size?

@kkeybbs
Copy link
Author

kkeybbs commented Oct 30, 2024

I'm not sure if the rules from app.Option like this app.MinSize(0, 0)?
So MinSize != {0, 0} and MaxSize != {0, 0} will always be true.

// MinSize sets the minimum size of the window.
func MinSize(w, h unit.Dp) Option {
	if w <= 0 {
		panic("width must be larger than or equal to 0")
	}
	if h <= 0 {
		panic("height must be larger than or equal to 0")
	}
	return func(m unit.Metric, cnf *Config) {
		cnf.MinSize = image.Point{
			X: m.Dp(w),
			Y: m.Dp(h),
		}
	}
}

While windows always match the rule MinSize != {0, 0}, most users want to show the minimize button, only a few want to hide, so we still need an option app.HiddenMinimizeButton(true)

@eliasnaur
Copy link
Contributor

If you're saying there's no way to revert to no MinSize once a MinSize has been set, then yes. It seems to me Gio will need to allow app.MinSize(0, 0) to mean "remove min size cosntraint". Same with app.MaxSize.

Would you like to contribute that change as well?

@kkeybbs
Copy link
Author

kkeybbs commented Dec 13, 2024

You are right as the initial size may be {0, 0}, or Gio change this cosntraint.

But when using MinSize != {0, 0}, most users just want to make the window not too small, and still keep the minimize button. Only few users want to hide/disable it.

And changing the rules change the default window-style which the most users expected.
Explicit options to hide minimize and maximize buttons are good for the most.

Copy link
Contributor

@eliasnaur eliasnaur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your point about the minimize button. I've left a review on your change.

@kkeybbs kkeybbs force-pushed the main branch 3 times, most recently from 1997c68 to 732c4ec Compare March 7, 2025 01:37
@kkeybbs
Copy link
Author

kkeybbs commented Jun 21, 2025

I've resolved conflicts with newest code from branch main, the pr commits is clean now.

@eliasnaur
Copy link
Contributor

Right, so I'm back to the question: when are you going to use HiddenMaximizeButton?

@kkeybbs
Copy link
Author

kkeybbs commented Jul 7, 2025

An about dialog like this:

  • image
  • thought some apps show two gray buttons like this:
  • (but I prefer hidding instead of disabling buttons, it looks nice.)
  • image

or a simple fixed size main dialog window like this:

  • image

The app.MaxSize and app.MinSize still can be set on demand.

In fact I have already rebuilt my qt app in business, with gioui.
image

@eliasnaur
Copy link
Contributor

An about dialog like this:

* <img alt="image" width="211" src="https://private-user-images.githubusercontent.com/3032421/458834958-76db1b9c-738e-4e41-b611-fb98c5ee7f55.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTE4Nzc4OTcsIm5iZiI6MTc1MTg3NzU5NywicGF0aCI6Ii8zMDMyNDIxLzQ1ODgzNDk1OC03NmRiMWI5Yy03MzhlLTRlNDEtYjYxMS1mYjk4YzVlZTdmNTUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDcwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTA3MDdUMDgzOTU3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTUxNjc5NGVkOTdhMjg2NTc4ODIwNjAxMmJiODM3OGZmZjQ5M2E2MzdjZmIyNzU4MDdlNWY2M2VlMzBmYWYyNyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.-tcUzAolNQetbNHjg4kjsclpbuQXfTB5SiKe2XJLmcc">

* thought some apps show two gray buttons like this:

* (but I prefer hidding instead of disabling buttons, it looks nice.)

* <img alt="image" width="508" src="https://private-user-images.githubusercontent.com/3032421/462996982-dd1ed888-a301-4bd9-8413-b46b2d94a2f3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTE4Nzc4OTcsIm5iZiI6MTc1MTg3NzU5NywicGF0aCI6Ii8zMDMyNDIxLzQ2Mjk5Njk4Mi1kZDFlZDg4OC1hMzAxLTRiZDktODQxMy1iNDZiMmQ5NGEyZjMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDcwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTA3MDdUMDgzOTU3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MDQxOGMzNWY3Y2ZkOTM2YmY0ZmY4YTAwMjIyMTYyN2M5OWZmM2ZkMGEwNjZlYWVmNjFhNjI3ZDZiNjAwNjU1OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.0GZ8vHAoL9TnKOvg4QYbRyN-3Ypizv4Ng4VfE4ncqfg">

or a simple fixed size main dialog window like this:

* <img alt="image" width="184" src="https://private-user-images.githubusercontent.com/3032421/458835002-0233a136-d621-45e0-9d14-378d05870848.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTE4Nzc4OTcsIm5iZiI6MTc1MTg3NzU5NywicGF0aCI6Ii8zMDMyNDIxLzQ1ODgzNTAwMi0wMjMzYTEzNi1kNjIxLTQ1ZTAtOWQxNC0zNzhkMDU4NzA4NDgucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDcwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTA3MDdUMDgzOTU3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NjUxZjg2NDM2OWE4YzAyOTg4N2UxZDE5ZjkwMDJiZjczZDU2ZGMyMzhlZWNmODM1ZDc3MjM1YjgzNTZhN2ZiYSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.IHhffZECAvRWpxmGAWFGvUf0qhMxQOTTRdoT7xsBuJU">

The app.MaxSize and app.MinSize still can be set on demand.

In fact I have already rebuilt my qt app in business, with gioui. image

Which of your examples are resizable? That is, have MinSize != MaxSize? Remember, we can (and should) automatically hide the maximize button when MinSize == MaxSize.

@kkeybbs
Copy link
Author

kkeybbs commented Jul 8, 2025

Yes, I've found none.
I agree with you, and I have merged that commit from upstream already.
image

It seems we should remove this option MaximizeButtonHidden?

And should we have the same implementation (automatically hide the button) on macOS instead of these changes?
image

It's quite a lot of changes.

@eliasnaur
Copy link
Contributor

Yes, I've found none. I agree with you, and I have merged that commit from upstream already. image

It seems we should remove this option MaximizeButtonHidden?

Yes, I think MaximizeButtonHidden should be left out. We can always add it later, if we find a need for it.

And should we have the same implementation (automatically hide the button) on macOS instead of these changes? image

It's quite a lot of changes.

Yeah, hiding the maximize button on macOS like on Windows seems like a good idea. I suggest doing that as a separate PR, to keep this PR about the MinimizeButtonHidden.

Aside: should the name be MinimizeDisabled to reflect the intention? Gio may end up doing more than just the button, such as disabling minimize keyboard shortcuts, greying instead of hiding etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants